package com.avic.rong.questionOrAnswer.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.avic.rong.R;
import com.avic.rong.questionOrAnswer.ArticleViewHolder;
import com.avic.rong.questionOrAnswer.bean.ArticleBean;

import java.util.List;

/**
 * Created by XinEr on 2019/8/7.
 * Describe:
 */
public class ArticleListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context context;
    private List<ArticleBean> listData;

    public ArticleListAdapter( Context context, List<ArticleBean> listData) {
        this.context = context;
        this.listData = listData;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.article_list_item, viewGroup, false);
        ArticleViewHolder viewHolder = new ArticleViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
        ArticleBean articleBean = listData.get(i);
        if (viewHolder instanceof ArticleViewHolder) {
            ((ArticleViewHolder) viewHolder).setData(articleBean,context);
            viewHolder.setIsRecyclable(false);
        }

        if (listData != null){
            if (listData.size() - 1 == i){
                ((ArticleViewHolder)viewHolder).line.setVisibility(View.GONE);
            }else{
                ((ArticleViewHolder)viewHolder).line.setVisibility(View.VISIBLE);
            }
        }

    }

  /*  @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
        this.viewHolder=viewHolder;
        ArticleBean articleBean = listData.get(i);
        //TODO 接口数据有问题缺少字段
//        GlideUtils.loaderImage(context,articleBean.get);
        viewHolder.tv_name.setText(articleBean.getAuthor());
        viewHolder.tv_date.setText(articleBean.getPublicTime()+"");
        viewHolder.tv_content.setText(articleBean.getTitle());
        viewHolder.tv_comment_num.setText(articleBean.getAppraiseNum()+"");
        viewHolder.tv_collect_num.setText(articleBean.getCollectNum()+"");
        viewHolder.tv_zan_num.setText(articleBean.getThumb()+"");
        thumb = articleBean.getThumb();
        if (clickZan){
            viewHolder.iv_zan.setRJCPSelected(true);
        }else {
            viewHolder.iv_zan.setRJCPSelected(false);
        }
        //点赞
        viewHolder.tv_zan_num.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int contId = articleBean.getContId();
                zanReq(contId);

            }
        });

    }*/



    @Override
    public int getItemCount() {
        return listData.size();
    }



}
